/**
 * 
 */
package problem.array;

import java.util.Arrays;
import java.util.Collections;

/**
 * @author Jun
 *
 */
public class BigIntegerOp {

	private char[] _optor;
	
	private int _len = 0;
	
	public BigIntegerOp(String str){
		
		if(str!= null){
			StringBuilder strb = new StringBuilder(str);
			this._optor = strb.reverse().toString().toCharArray();
			this._len = _optor.length;
		}
	}
	
	public BigIntegerOp(char[] charr){
		
		if(charr!= null){
			_optor = charr;
			_len = charr.length;
		}
		
	}
	
	@Override
	public String toString(){
		
		Collections.reverse(Arrays.asList(_optor));
		return new String(_optor);
	}
	
	public BigIntegerOp Add(BigIntegerOp second){
		
		int carry = 0;
		int npos = 0;	
		BigIntegerOp max = this;
		BigIntegerOp min = second;
		if (this._len < second._len){
			max = second;
			min = this;
		}
		int minlen = min._len;			
		char zeroasici = '0';
		StringBuilder result = new StringBuilder();
		
		char leftch = '0';
		char rch = '0';
		for(int i=0;i< max._len;i++){
			leftch = max._optor[i];
			if( i < min._len)
				rch = min._optor[i];
			else
				rch = '0';
			int tmp = (leftch + rch+ carry - 2*zeroasici);
			char ctmp = '0';
			if(tmp > 9){
				carry = 1;
				ctmp += tmp-9;
				result.append(ctmp);
			}
			else {
				carry = 0;
				ctmp += tmp;
				result.append(ctmp);
			}
		}
		BigIntegerOp reBigIntegerOp = new BigIntegerOp(result.toString().toCharArray());
		
		return reBigIntegerOp;
	}
	
	public BigIntegerOp Substract(BigIntegerOp second){
		
		
		return null;
	}
	
	public BigIntegerOp Multiply(BigIntegerOp second){
		
		
		return null;
	}
	
	public BigIntegerOp Divide(BigIntegerOp second){
		
		
		return null;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		BigIntegerOp one = new BigIntegerOp("11");
		BigIntegerOp two = new BigIntegerOp("11");
		
		BigIntegerOp three = one.Add(two);
		
		System.out.println(three.toString());

	}

}
